package com.itheima.info.manger.teacherdao;

import com.itheima.info.manger.domain.Teacher;

public class TeacherDao {
    private static Teacher[] teachers = new Teacher[5];

    public boolean addTeacher(Teacher teacher) {
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
           if (teachers[i] == null){
               index = i;
               break;
           }
        }
        if (index == -1){
            return false;
        }else {
            teachers[index] = teacher;
            return true;
        }
    }

    public Teacher[] findAllTeacher() {
        return teachers;
    }

    public boolean deleteTeacher(String id) {
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null && teachers[i].getId().equals(id)){
                teachers[i] = null;
                return true;
            }
        }
        return false;
    }

    public boolean updateTeacher(Teacher teacher) {
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null && teachers[i].getId().equals(teacher.getId())){
                teachers[i] = teacher;
                return true;
            }
        }
        return false;
    }
}
